package org.qydjk.console.controller.demo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.qydjk.common.controller.BaseController;
import org.qydjk.common.util.RedisTemplateUtil;
import org.qydjk.common.util.SpringContextUtil;
import org.qydjk.common.util.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/demo")
public class DemoController extends BaseController{
    @RequestMapping("/sp.do")
    public void sp(){
        RedisTemplateUtil redisTemplateUtil = (RedisTemplateUtil) SpringContextUtil.getBean("redisTemplateUtil");
        System.out.println(redisTemplateUtil);
    }

    @RequestMapping("/ue.do")
    public String ue(){
        return "demo/ueditor";

    }

    @RequestMapping("/combotree.do")
    public String ztree(){
        return "demo/comboTree";
    }

    @RequestMapping("/autoComplete.do")
    public String autoComplete(){
        return "demo/autocomplete";
    }

    @RequestMapping("/autoCompleteData.do")
    @ResponseBody
    public JSONObject autoCompleteData(){
        String query = request.getParameter("query");
        System.out.println(query);
        if(!StringUtil.isEmptyOrNull(query)){
            JSONArray arr = new JSONArray();
            JSONObject j1 = new JSONObject();
            j1.put("value","Auto");
            j1.put("data","a1");

            JSONObject j2 = new JSONObject();
            j2.put("value","Ask");
            j2.put("data","a2");

            JSONObject j3 = new JSONObject();
            j3.put("value","Bottom");
            j3.put("data","b1");

            JSONObject j4 = new JSONObject();
            j4.put("value","Button");
            j4.put("data","b2");

            JSONObject j5 = new JSONObject();
            j5.put("value","ABC");
            j5.put("data","c");

            arr.add(j1);
            arr.add(j2);
            arr.add(j3);
            arr.add(j4);
            arr.add(j5);

            JSONObject obj = new JSONObject();
            obj.put("suggestions",arr);
            return obj;
        }
        return null;
    }
}
